﻿using System;
using System.Configuration;
using System.Collections.Generic;
using IGolovkine.ShoutCastRipper;
using IGolovkine.Core.Diagnostics;

namespace IGolovkine.ShoutCastRipper.Service.Configuration
{
    public class StationRipperElement : ConfigurationElement
    {
        private const string NameTag = "name";
        private const string UrlTag = "url";
        private const string UserAgentTag = "userAgent";
        
        private const string ContentTitleProbingFrequencyTag = "contentTitleProbingFrequency";

        private const string MaximumLengthTag = "maximumLength";
        private const string MinimumLengthTag = "minimumLength";

        private const string MaximumAgeTag = "maximumAge";
        private const string LoggerParameterTag = "loggerParameter";
        private const string contentTitleRegexFiltersTag = "contentTitleRegexFilters";
        private const string FileRepositoryTag = "fileRepository";
        private const string DatePatternsTag = "datePatterns";

        [ConfigurationProperty(NameTag, IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)this[NameTag]; }
        }

        [ConfigurationProperty(UrlTag, IsRequired = true)]
        public string Url
        {
            get { return (string)this[UrlTag]; }
        }

        [ConfigurationProperty(UserAgentTag, IsRequired = true)]
        public string UserAgent
        {
            get { return (string)this[UserAgentTag]; }
        }
                
        [ConfigurationProperty(ContentTitleProbingFrequencyTag, IsRequired = true)]
        public TimeSpan ContentTitleProbingFrequency
        {
            get { return (TimeSpan)this[ContentTitleProbingFrequencyTag]; }
        }

        [ConfigurationProperty(MaximumLengthTag, IsRequired = true)]
        public TimeSpan MaximumLength
        {
            get { return (TimeSpan)this[MaximumLengthTag]; }
        }

        [ConfigurationProperty(MinimumLengthTag, IsRequired = true)]
        public TimeSpan MinimumLength
        {
            get { return (TimeSpan)this[MinimumLengthTag]; }
        }

        [ConfigurationProperty(MaximumAgeTag, IsRequired = true)]
        public TimeSpan MaximumAge
        {
            get { return (TimeSpan)this[MaximumAgeTag]; }
        }

        [ConfigurationProperty(LoggerParameterTag, IsRequired = true)]
        public string LoggerParameter
        {
            get { return (string)this[LoggerParameterTag]; }
        }

        [ConfigurationProperty(contentTitleRegexFiltersTag, IsRequired = true)]
        public ContentTitleRegexFilterElementCollection ContentTitleRegexFilters
        {
            get { return (ContentTitleRegexFilterElementCollection) this[contentTitleRegexFiltersTag]; }
        }

        [ConfigurationProperty(DatePatternsTag, IsRequired = false)]
        public DatePatternElementCollection DatePatterns
        {
            get { return (DatePatternElementCollection) this[DatePatternsTag]; }
        }

        [ConfigurationProperty(FileRepositoryTag, IsRequired = false)]
        public FileRepositoryElement FileRepository
        {
            get { return (FileRepositoryElement)this[FileRepositoryTag]; }
        }

        public override string ToString()
        {
            return ObjectDumper.Format(this);
        }

        public override bool IsReadOnly()
        {
            return false;
        }
    }
}
